﻿using CCSSolderUI.Common.Domain;
using Microsoft.EntityFrameworkCore;

namespace CCSSolderUI
{
    public class SysDBContext : DbContext
    {
        public DbSet<BarcodeSyntax> BarcodeSyntaxs { get; set; }
        public DbSet<UserBarcode> UserBarcodes { get; set; }
        protected override void OnConfiguring(DbContextOptionsBuilder options)
        {
            var path = System.AppDomain.CurrentDomain.BaseDirectory;
            string DbPath = System.IO.Path.Join(path, "SysDB.db");
            options.UseSqlite($"Data Source={DbPath};Pooling=False");
        }
        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            modelBuilder.Entity<BarcodeSyntax>(entity =>
            {
                entity.HasKey(e => e.Id);
                entity.Property(e => e.Head).HasMaxLength(40);
                entity.Property(e => e.PartName).HasMaxLength(100);
            });
            modelBuilder.Entity<UserBarcode>(entity =>
            {
                entity.HasKey(e => e.Id);
                entity.Property(e => e.Barcode).HasMaxLength(40);
            });
        }
    }
}
